package com.supervision.manage.controller.case

import com.fly.base.common.DataResponse
import com.fly.base.controller.BaseController
import com.supervision.domain.bean.po.CourtOrgSearchPO
import com.supervision.domain.model.CourtOrg
import com.supervision.manage.service.CourtOrgService
import io.swagger.annotations.Api
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestMethod
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.RestController

/**
 *  Created by whis on 2019-06-18
 */
@RestController
@RequestMapping("/client/1/courtOrg")
@Api(tags = ["法院"])
class CourtOrgController : BaseController() {

    @Autowired
    lateinit var courtOrgService: CourtOrgService

    @RequestMapping("list", method = [(RequestMethod.GET)])
    fun list(po: CourtOrgSearchPO): DataResponse {
        val data = courtOrgService.getCourtOrgList(po)
        return DataResponse.create().putAll(data)
    }

    @RequestMapping("detail", method = [(RequestMethod.GET)])
    fun detail(@RequestParam("id") id: Long): DataResponse {
        val courtOrg = CourtOrg.findOrFail(id)
        return DataResponse.create().put("courtOrg", courtOrg)
    }

    @RequestMapping("delete", method = [(RequestMethod.POST)])
    fun delete(@RequestParam("id") id: Long): DataResponse {
        CourtOrg.findById(id)?.delete()
        return DataResponse.create()
    }

    @RequestMapping("save", method = [(RequestMethod.POST)])
    fun save(courtOrg: CourtOrg): DataResponse {
        courtOrgService.save(courtOrg)
        return DataResponse.create()
    }

}
